package com.manager.core.module.manager.service;

import com.manager.commons.encrypt.md5.MD5;
import com.manager.commons.mybatis.dao.GenericDao;
import com.manager.commons.mybatis.service.GenericService;
import com.manager.core.web.json.AjaxJson;
import com.manager.user.module.platform.core.dao.PlatformUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class MainService extends GenericService<String> {
    @Autowired
    private PlatformUserDao puDao;


    @Override
    public GenericDao<String> getDao() {
        return null;
    }

    @Override
    public String getModel() {
        return "";
    }

    public Map<String, Object> findAccountView(Map<String, Object> map) {
        return puDao.findAccountView(map);
    }

    public Integer querEditPermission(Map<String, Object> map) {
        return puDao.querEditPermission(map);
    }

    public Integer querDownPermission(Map<String, Object> map) {
        return puDao.querDownPermission(map);
    }

    /**
     * 重置密码
     *
     * @param params
     * @return
     */
    public AjaxJson updatePwd(Map<String, Object> params) {
        if (null != params) {
            String oldPwd = getParamsString(params, "oldPwd");
            String newPwd = getParamsString(params, "newPwd");
            String opwd = MD5.md5(oldPwd);
            String oldPwdf = puDao.findPwd(params);
            if (!opwd.equals(oldPwdf)) {
                return new AjaxJson(0, "原密码输入错误");
            }
            String npwd = MD5.md5(newPwd);
            params.put("pwd", npwd);
            int f = puDao.updatePwd(params);
            return new AjaxJson(f, "密码修改" + ((f > 0) ? "成功" : "失败！"));
        }
        return new AjaxJson("参数错误");
    }
}
